Specify which filename is causing an error if the filename is a
authorDavid Kimdon <dwhedon@gordian.com>
Sun, 1 Feb 2026 09:59:08 +0000 (10:59 +0100)
committerMatthias Klose <doko@debian.org>
Sun, 1 Feb 2026 09:59:08 +0000 (10:59 +0100)
directory. (#45832)

Gbp-Pq: Name 006_better_file_error.patch

bfd/opncls.c

index 8bbbcd5d326b5bc0dfca6edcfa1d1b61ab431733..a3ae9bf5e6cebc9ef48ca97b0073b3593f253a1f 100644 (file)
@@ -232,6 +232,13 @@ bfd_fopen (const char *filename, const char *target, const char *mode, int fd)
 {
   bfd *nbfd;
   const bfd_target *target_vec;
+  struct stat s;
+
+  if (stat (filename, &s) == 0)
+    if (S_ISDIR(s.st_mode)) {
+      bfd_set_error (bfd_error_file_not_recognized);
+      return NULL;
+    }
 
   nbfd = _bfd_new_bfd ();
   if (nbfd == NULL)